<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/icon/iconfont.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/icon/iconfont2.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/login.css') }}">
    <script type="text/javascript" src="{{ url_for('static',filename='js/jquery-3.6.0.min.js') }}"></script>
    <!-- layui样式文件 -->
    <link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/layui/2.5.7/css/layui.min.css">
    <!-- layui脚本文件 -->
    <script src="//cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.min.js"></script>
</head>
<body>
<div class="main-content">
    <div class="formDiv">
        <h2 class="text-center" style="font-weight: bold;font-size: 24px">网上书店登录</h2>
        {#form表单#}
        <form id="loginForm" method="post" action="{{ url_for('auth.login1') }}">
            <div class="dataform">
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-yonghu1"></span>
                    <input id="userName" name="userName" type="text" class="inputs" placeholder="请输入学号" maxlength="64">
                </div>
                <div class="error-content">
                    <span id="userNameErr" class="errMsg"></span>
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-mima"></span>
                    <input class="inputs" type="password" name="pwd" placeholder="请输入密码" id="pwd" maxlength="20">
                </div>
                <div class="error-content">
                    <span id="passwordErr" class="errMsg"></span>
                </div>
                <div class="btn-warp gap">
                    <div class="text-center">
                        <input type="hidden" value="jsform" id="_app"/>
                        <button type="submit" id="btnLogin" class="btn btn-block lgbtn blue">登录</button>
                    </div>
                </div>
                <div class="gap">
                    <div class="pull-right" style="margin-top: 6px"><a href="{{ url_for('person.forgetPass1') }}" class="link">忘记密码</a><span class="split-space">|</span><a href="{{ url_for('auth.register1') }}" class="link">新用户注册</a></div>
                    <div class="pretty-box">
                        <input type="checkbox" value="1" name="REMEMBER" id="remember" class="">
                        <label for="remember" style="font-weight: normal">记住我</label>
                    </div>
                </div>
                <div style="margin-top: 20px;text-align: center"><a href="{{ url_for('admin.adminlogin') }}" style="font-size:13px;display: inline-block;color: cornflowerblue">管理员入口</a></div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        {#表单提交进行登录#}
        $("#loginForm").submit(function (event) {
            event.preventDefault();
            var formData = $(this).serialize();
            console.log(formData);
            {#ajax请求参数是表单内容#}
            $.ajax({
                url:"/auth/login1",
                type:"post",
                data:formData,
                success:function (res){
                    if(res.state==200){     {#成功跳转到首页#}
                        layer.msg('登录成功！',{
                            icon: 1,
                            time: 1000
                        },function () {
                            window.location.href="{{ url_for('index.index') }}"
                        });
                    }else {     {#失败重定向到登录页面#}
                        layer.msg(res.msg,{
                            icon: 2,
                            time: 1000
                        },function () {
                            window.location.href="{{ url_for('hello') }}"
                        });
                    }
                }
            });
        });
    });
</script>
</body>
</html>